//
//  FDApplyCell.m
//  FamousDoctorOnline
//
//  Created by Cain on 16/7/7.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDApplyCell.h"
#import <Masonry.h>
#import "FDApplyModel.h"
#import "UILabel+FDExtension.h"

@interface FDApplyCell ()
//病人文本框
@property (nonatomic , weak)UILabel *patientsLabel;
//就诊时间文本框
@property (nonatomic , weak)UILabel *timeLabel;
//审核按钮
@property (nonatomic , weak)UIButton *checkButton;
//分割线
@property (nonatomic , weak)UIView *lineView;
//医生文本框
@property (nonatomic , weak)UILabel *doctorLabel;
//医院文本框
@property (nonatomic , weak)UILabel *hospitalLabel;

@end

@implementation FDApplyCell

/**重写初始化方法*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
        [self setupLayout];
    }
    return self;
}

/**创建cell控件*/
- (void)setupUI
{
    //病人
    UILabel *patientsLabel = [UILabel setCustomLabel];
    self.patientsLabel = patientsLabel;
    [self.contentView addSubview:patientsLabel];
    
    //就诊时间
    UILabel *timeLabel = [UILabel setCustomLabel];
    self.timeLabel = timeLabel;
    [self.contentView addSubview:timeLabel];
    
    //审核按钮
    UIButton *checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.checkButton = checkButton;
    checkButton.layer.cornerRadius = SCREEN_WIDTH*0.1;
    checkButton.clipsToBounds = YES;
    [checkButton setBackgroundColor:[UIColor colorWithRed:30/255.0 green:188/255.0 blue:188/255.0 alpha:1]];
    [checkButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.contentView addSubview:checkButton];
    
    //分割线
    UIView *lineView = [[UIView alloc]init];
    self.lineView = lineView;
    lineView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:lineView];
    
    //医生文本框
    UILabel *doctorLabel = [UILabel setCustomLabel];
    self.doctorLabel = doctorLabel;
    [self.contentView addSubview:doctorLabel];
    
    //医院文本框
    UILabel *hospitalLabel = [UILabel setCustomLabel];
    self.hospitalLabel = hospitalLabel;
    [self.contentView addSubview:hospitalLabel];
    
}

/**设置控件约束*/
- (void)setupLayout
{
    //病人文本框约束
    [self.patientsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.lineView.mas_top).offset(-10);
        make.left.mas_equalTo(10);
    }];
    //就诊时间文本框约束
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.patientsLabel.mas_top);
        make.left.mas_equalTo(self.patientsLabel.mas_right).offset(SCREEN_WIDTH*0.1);
    }];
    //审核按钮约束
    [self.checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH*0.2, SCREEN_WIDTH*0.2));
        make.right.offset(0);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
    
    //分割线约束
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.checkButton.mas_centerY);
        make.left.offset(20);
        make.right.equalTo(self.checkButton.mas_left);
        make.height.mas_equalTo(1);
    }];
    
    //医生文本框约束
    [self.doctorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(10);
        make.left.equalTo(self.patientsLabel.mas_left);
    }];
    
    //医院文本框约束
    [self.hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeLabel.mas_left);
        make.centerY.mas_equalTo(self.doctorLabel.mas_centerY);
    }];
}

/**为控件赋值*/
- (void)setApplyModel:(FDApplyModel *)applyModel {
    _applyModel = applyModel;
    self.patientsLabel.text = applyModel.patients;
    self.timeLabel.text = applyModel.time;
    [self.checkButton setTitle:applyModel.check forState:UIControlStateNormal];
    self.doctorLabel.text = applyModel.doctor;
    self.hospitalLabel.text = applyModel.hospital;
}

@end
